<template lang="html">
  <div class="contain-body clearfix">
    <div class="form-group">
      <span class="text-title">是否认证：</span>
      <el-radio class="radio" v-model="params.is_cecdc" :label='1'>诚信认证企业</el-radio>
      <el-radio class="radio" v-model="params.is_cecdc" :label='0'>普通企业</el-radio>
    </div>
    <div class="form-group">
      <span class="text-title">是否曝光：</span>
      <el-radio class="radio" v-model="params.is_exposure" :label='1'>曝光企业</el-radio>
      <el-radio class="radio" v-model="params.is_exposure" :label='0'>未曝光企业</el-radio>
    </div>
    <div class="form-group">
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <span class="text-title">企业名称：</span>
          <el-input v-model="params.name" placeholder='请输入企业名称'></el-input>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="grid-content bg-purple-light">
          <span class="text-title">企业类型：</span>
          <el-select v-model="params.company_type" placeholder="请选择公司类型">
            <el-option label="无类型" :value='0'></el-option>
            <el-option v-for='item in typeList' :label="item.name" :value="item.id" :key='item.id'></el-option>
          </el-select>
        </div>
      </el-col>
    </div>
    <div class="form-group">
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <span class="text-title">公司经营状态：</span>
          <el-select style='width: 20%' v-model='params.state'>
            <el-option label="存续" :value="0"></el-option>
            <el-option label="吊销" :value="1"></el-option>
            <el-option label="注销" :value="2"></el-option>
          </el-select>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <span class="text-title">企业曾用名：</span>
          <el-input v-model="params.oldName" placeholder='请输入曾用名'></el-input>
        </div>
      </el-col>
    </div>
    <div class="form-group">
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <span class="text-title">企业法人：</span>
          <el-input v-model="params.corporation" placeholder='请输入企业法人'></el-input>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <span class="text-title">企业地址：</span>
          <el-input v-model="params.address" placeholder='请输入企业地址'></el-input>
        </div>
      </el-col>
    </div>
    <div class="form-group">
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <span class="text-title">注册资金：</span>
          <el-input v-model="params.capital" placeholder='请输入注册资金' style='width: 45%'></el-input>
          <el-select style='width: 20%;margin-left: 4%' v-model='params.capital_type'>
            <el-option label="未知" :value="0"></el-option>
            <el-option label="人民币" :value="1"></el-option>
            <el-option label="美元" :value="2"></el-option>
          </el-select>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <span class="text-title">营业期限：</span>
          <el-date-picker
            v-model="params.business_date"
            type="daterange"
            placeholder="选择日期范围">
          </el-date-picker>
        </div>
      </el-col>
    </div>
    <div class="form-group">
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <span class="text-title">成立时间：</span>
          <el-date-picker type="date" placeholder="选择日期" v-model="params.creation_date"></el-date-picker>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <span class="text-title">发照日期：</span>
          <el-date-picker type="date" placeholder="选择日期"  v-model="params.approved_date"></el-date-picker>
        </div>
      </el-col>
    </div>
    <div class="form-group">
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <span class="text-title">注册号：</span>
          <el-input v-model="params.business_id" placeholder='请输入注册号'></el-input>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <span class="text-title">登录机关：</span>
          <el-input v-model="params.commercial_bureau" placeholder='请输入登录机关'></el-input>
        </div>
      </el-col>
    </div>
    <div class="form-group">
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <span class="text-title">组织机构代码：</span>
          <el-input v-model="params.organization_code" placeholder='请输入组织机构代码'></el-input>
        </div>
        <div class="grid-content bg-purple">
          <span class="text-title">信用社会代码：</span>
          <el-input v-model="params.credit_code" placeholder='请输入信用社会代码'></el-input>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <span class="text-title">经营范围：</span>
          <el-input type="textarea" v-model="params.business_scope" style='width: 70%;min-height: 80px'></el-input>
        </div>
      </el-col>
    </div>
    <div class="el-button el-button--theme save-btn" @click='saveCompany'>保存</div>
  </div>
</template>

<script>
export default {
  props: ['data'],
  data () {
    return {
      params: {
        name: '',
        oldName: '',
        is_cecdc: 1,
        is_exposure: 1,
        company_type: 1,
        corporation: '',
        address: '',
        business_date: [],
        creation_date: '',
        approved_date: '',
        business_id: '',
        organization_code: '',
        credit_code: '',
        business_scope: '',
        capital_type: 1,
        capital: '',
        state: 0,
        commercial_bureau: ''
      },
      typeList: [
      ]
    }
  },
  mounted () {
    this.data.title = this.$route.query.id ? '企业修改' : '企业添加'
    this.getCompanyType()
  },
  methods: {
    getDetail () {
      this.$http('get', 'company', {id: this.$route.query.id})
      .then((data) => {
        if (data.code === 1) {
            this.params = data.result
        }
      })
    },
    getCompanyType () {
      this.$http('get', 'companyType')
      .then((data) => {
        this.typeList = data.result
        this.$route.query.id && this.getDetail()
      })
    },
    saveCompany () {
      this.$http('put', 'company', this.params)
        .then((data) => {
         this.$route.query.id && this.getDetail()
          this.$message({
            message: '提交成功',
            type: 'success'
          })
          this.$router.push({ path: 'list' })
        })
    }
  }
}
</script>

<style lang="less">
.save-btn{
  margin-top: 40px;
  margin-left: 50%;
}
</style>
